import React from 'react'
import $ from  'jquery'
import {setCookie,getCookie} from "../../util/util";
import PropTypes from 'prop-types';
import {connect} from 'react-redux'
import  {Button,TabBar } from  'antd-mobile'
import HomeTop from  './subpage/HomeTop/HomeTop'
import  TodayNews from  './subpage/TodayNews/TodayNews'
import  SeckillArea from './subpage/SeckillArea/SeckillArea'
import  HomeAd from './subpage/HomeAd/HomeAd'
import  VipAd from './subpage/VipAd/VipAd'
import  MainTabBar from  '../../components/MainTabBar'
import  Swiper_2 from  '../../components/Swiper_2/Swiper_2'
import HomeClass from  './subpage/HomeClass/HomeClass'
import  {getProduct_Index_List} from  '../../redux/product_index/product_index.redux'
import  {AjaxSend} from "../../util/util";
import FineRecommended from "./subpage/FineRecommended/FineRecommended";
import PopularRecommended from  "./subpage/PopularRecommended/PopularRecommended";
import  './css/index.css'
import  startLogo from  '../../static/img/start.jpg'
import Toast from "../../components/Toast"
// 装饰器模式
@connect(
    state=>state.userlist,
    {getProduct_Index_List}
)
class Index extends React.Component{
    constructor(props){
        super(props)
        this.state = {
            data: ['', '', ''],
            Ad_logo1:require('./subpage/HomeAd/img/ad_1.png'),
            HomeTopSwiper:[],
            HomeTopSwiperData:[],
            HomeTopClassData:[],
            UserInfo:'',
            HomeAd_120:[],
            HomeAd_121:[],
            VipAdData:[],
            swiper_2_data:[],
            HomeClass_data:[],
            FineRecommended:[],
            FineRecommended_class_id:'',
            SeckillArea:{},
            PopularRecommended:[],
            TodayNews:[],
            user_code:'',
            indexBg:false
        };
    }
    componentWillMount(){
        this.getProduceIndexData()
        this.getUserInfoData()
        this.get_product_filter_113()
        this.setSartLogo()
    }
    setSartLogo(){
        if (getCookie('indexbg') != '1') {
            this.setState({
                indexBg:true
            })
            var _this=this
            setTimeout(function() {
                setCookie('indexbg', '1')
                _this.setState({
                    indexBg:false
                })
            }, 2000)
        }

    }
    indexBg() {
        this.setState({
            indexBg:false
        })
         setCookie('indexbg', '1')

    }
    getUserInfoData(){
        const data={
            _cmd: 'usercenter_index'
        }
        AjaxSend(data, (da) =>  {
            this.setState({
                UserInfo:da.data,
                user_code:da.data.base64_mobile
            })
        }, (errors)  => {
            alert(errors);
        })
    }
    get_product_filter_113(){
        var data={
            _cmd:'product_product_filter',
            page:1,
            rows:'50',
            class_id:113
        }
        AjaxSend(data, (da) =>  {
            this.setState({
                PopularRecommended:da.data
            })
        }, (errors)  => {
            alert(errors);
        })
    }
    getProduceIndexData(){
        const data={
            _cmd: 'product_index2'
        }
        AjaxSend(data, (da) =>  {
            this.setState({
                data:da.data,
                HomeTopSwiperData:da.data.class[101].children,
                HomeTopClassData:da.data.class[104].children,
                VipAdData:da.data.class[110].children,
                HomeAd_120:da.data.class[120],
                HomeAd_121:da.data.class[121],
                swiper_2_data:da.data.class[300].children,
                HomeClass_data:da.data.class[301].children,
                FineRecommended:da.data.class[112].children2,
                FineRecommended_class_id:da.data.class[112].class_id,
                SeckillArea:da.data.class[123],
                TodayNews:da.data.class[122].children,

            })
        }, (errors)  => {
            alert(errors);
        })
    }
    componentDidMount() {
        this.props.getProduct_Index_List()
    }
    componentWillReceiveProps(nextProps){

    }
    render(){
        return (
            <div>
                <HomeTop user_code={this.state.user_code} HomeTopSwiperData={this.state.HomeTopSwiperData} HomeTopClassData={this.state.HomeTopClassData} />
                <TodayNews TodayNews={this.state.TodayNews}/>
                <SeckillArea SeckillArea={this.state.SeckillArea}/>
                <HomeAd data={this.state.HomeAd_120}/>
                <VipAd  data={this.state.VipAdData}/>
                <Swiper_2 swiper_2_data={this.state.swiper_2_data}/>
                <HomeAd  data={this.state.HomeAd_121}/>
                <HomeClass HomeClass_data={this.state.HomeClass_data}/>
                <FineRecommended FineRecommended_class_id={this.state.FineRecommended_class_id} FineRecommended={this.state.FineRecommended}/>
                <PopularRecommended  PopularRecommended={this.state.PopularRecommended}/>
                <MainTabBar/>
                <Toast ref="getChildMethod" />
                {this.state.indexBg? <div className="indexBg"
                                           onClick={()=>{this.indexBg()}}
                                           style={{
                                               width: '100vw',
                                               height: '100vh',
                                               zIndex:'9999',
                                               position:'fixed',
                                               top:'0',
                                               backgroundSize:'cover',
                                               background: 'url('+startLogo+') center center /  100vw 100vh no-repeat' }}>
                    > </div>:<span></span>
                }


            </div>
        )
    }
}


export default Index
